<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>Document</title>
</head>
<body>

  <div id='app'>
    <home></home>
  </div>

<template id="tpl">
  <div>
    <h2>我是HOME页</h2>
    <child1></child1>
      <hr>
    <child2></child2>
  </div>
</template>

<script src='https://cdn.bootcdn.net/ajax/libs/vue/2.6.12/vue.js'></script>
<script>
  // 创建一个第三方实例
  const bus = new Vue()
  const Child1 = {
    template: `
      <div>
        子组件1
        <button @click="emit">按钮1</button>
      </div>
    `
    ,data(){
      return {
        msg: '子组件1的数据'
      }
    }
    ,methods: {
      emit() {
        // 触发一个自定义事件
        bus.$emit('biubiubiu', this.msg)
      }
    }
  }
  const Child2 = {
    template: `
      <div>
        子组件2
        {{msg}}
      </div>
    `
    ,data(){
      return {
        msg: ''
      }
    }
    ,mounted(){
      bus.$on('biubiubiu', (msg)=> {
        this.msg = msg
      })
    }
  }
  const Home = {
    template: "#tpl"
    ,components: {
      Child1
      ,Child2
    }
    ,date() {
      return {
        msg: ''
      }
    }
  }
  Vue.component("Home", Home)
  const app = new Vue({
    el: '#app'
  })
</script>
</body>
</html>